package com.my.hotel.mapper;


import com.my.hotel.entity.serverPage.Article;
import com.my.hotel.util.ILog;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;
@Component
public interface ArticleMapper {
    @Select("select * from article")
    List<Article> getList();
    @Select("select * from article where articleId=#{id}")
    @Results({
            @Result(property = "formUser", column = "formUserId",
                    one = @One(select = "com.my.hotel.mapper.JdUserMapper.getClientById")),
            @Result(property = "toUser", column = "toUserId",
                    one = @One(select = "com.my.hotel.mapper.JdUserMapper.getClientById")),
            @Result(property = "child", column = "articleId",
                    many = @Many(select = "com.my.hotel.mapper.ArticleMapper.getChildById2"))
    })
    Article getArticle(int id);

    @ILog("添加客户")
    @Insert({"insert into tb_client values (null,#{content},#{userId},#{createDatetime},#{likeNum},#{state},#{parentId},#{star})"})

    void addOne(Article article);
    @Delete("delete from article where articleId=#{delId}")
    void delOneById(int delId);
    @Select("select * from article where parentId=#{id} ")
    @Results({
            @Result(property = "formUser", column = "formUserId",
                    one = @One(select = "com.my.hotel.mapper.JdUserMapper.getClientById")),
            @Result(property = "toUser", column = "toUserId",
                    one = @One(select = "com.my.hotel.mapper.JdUserMapper.getClientById")),
            @Result(property = "child", column = "articleId",
                    many = @Many(select = "com.my.hotel.mapper.ArticleMapper.getChildById2"))
    })
    List<Article> getChildById(int id);

    @Select("select * from article where parentId=#{id} ")
    @Results({
            @Result(property = "formUser", column = "formUserId",
                    one = @One(select = "com.my.hotel.mapper.JdUserMapper.getClientById")),
            @Result(property = "toUser", column = "toUserId",
                    one = @One(select = "com.my.hotel.mapper.JdUserMapper.getClientById")),
    })
    List<Article> getChildById2(int id);
//    @Update("update tb_client set username=#{username},nickname=#{username},imageUrl=#{imageUrl},realname=#{realname},gender=#{gender},birthday=#{birthday},password=${password}," +
//            "email=#{email},tel=#{tel},address=#{address} where id=#{id}")
//    void clientUpdate(Client client);
    @Select("select COUNT(*) from article where userId=#{userId}")
    int getCountByUserId(int userId);

@Select("SELECT SUM(likeNum) FROM jd_userlike")
    int countLikeNum();
@Select("select*from article where articleId=#{id}")
    Article getOne(int id);


}
